import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ReadFromDatabase {

	public void doExample() {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			Connection conn = DriverManager.getConnection(
			        "jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=GBK",
			        "root", "root");
			PreparedStatement prepareStatement = conn
			        .prepareStatement("select a,b,c from testtable");
			ResultSet resultSet = prepareStatement.executeQuery();

			while (resultSet.next()) {
				System.out.println(resultSet.getInt("a"));
				System.out.println(resultSet.getString("b"));
				System.out.println(resultSet.getInt("c"));
			}

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		ReadFromDatabase e = new ReadFromDatabase();
		e.doExample();
	}
}
